F90_UNIX_ENV

 

Index

NAME
USAGE
SYNOPSIS
PARAMETER DESCRIPTION
DERIVED-TYPE DESCRIPTION
PROCEDURE DESCRIPTIONS
SEE ALSO
BUGS
 

NAME

f90_unix_env - Module of Unix environment functions  

USAGE

USE F90_UNIX_ENV

This module contains part of a Fortran API to functions detailed in ISO/IEC 9945-1:1990 Portable Operating System Interface (POSIX) - Part 1: System Application Program Interface (API) [C Language].

The functions in this module are from Section 4: Process Environment, plus gethostname from 4.3BSD.

Error handling is described in F90_UNIX_ERRNO. Note that for procedures with an optional ERRNO argument, if an error occurs and ERRNO is not present, the program will be terminated.  

SYNOPSIS

Parameters
CLOCK_TICK_KIND, LONG_KIND, SC_STDIN_UNIT, SC_STDOUT_UNIT, SC_STDERR_UNIT, SC_ARG_MAX, SC_CHILD_MAX, SC_CLK_TCK, SC_NGROUPS_MAX, SC_SAVED_IDS, SC_VERSION, TIME_KIND
Derived Types
TMS, UTSNAME
Procedures
CLK_TCK, CTERMID, GETARG, GETEGID, GETENV, GETEUID, GETGID, GETGROUPS, GETLOGIN, GETPGRP, GETPID, GETPPID, GETUID, IARGC, ISATTY, SETGID, SETPGID, SETSID, SETUID, SYSCONF, TIME, TIMES, TTYNAME, UNAME
 

PARAMETER DESCRIPTION

INTEGER,PARAMETER :: CLOCK_TICK_KIND
The integer kind used for clock ticks (see TIMES).

INTEGER,PARAMETER :: LONG_KIND

The integer kind corresponding to the C type "long". This is used for the type of one of the arguments of SYSCONF.

INTEGER,PARAMETER :: SC_STDIN_UNIT, SC_STDOUT_UNIT, SC_STDERR_UNIT, SC_ARG_MAX, SC_CHILD_MAX, SC_CLK_TCK, SC_JOB_CONTROL, SC_OPEN_MAX, SC_NGROUPS_MAX, SC_SAVED_IDS, SC_STREAM_MAX, SC_TZNAME_MAX, SC_VERSION

Values used as arguments to SYSCONF. The following table describes the returned information from SYSCONF, this is not the value of the SC_* constant.
SC_STDIN_UNIT
The logical unit number for standard input (READ *,...).
SC_STDOUT_UNIT
The logical unit number for standard output (PRINT, WRITE(*,...)).
SC_STDERR_UNIT
The logical unit number on which errors are reported.
SC_ARG_MAX
Maximum length of arguments for the EXEC functions, in bytes, including environment data.
SC_CHILD_MAX
Maximum number of simultaneous processes for a single user.
SC_CLK_TCK
Number of clock ticks per second. (This is the same value returned by the CLK_TCK function).
SC_JOB_CONTROL
Value available only if job control is supported by the operating system.
SC_NGROUPS_MAX
Maximum number of simultaneous supplementary group IDs per process.
SC_OPEN_MAX
Maximum number of files open simultaneously by a single process.
SC_SAVED_IDS
Value available only if each process has a saved set-uid and set-gid.
SC_STREAM_MAX
Maximum number of logical units that can be simultaneously open. Not always available.
SC_TZNAME_MAX
Maximum number of characters for the name of a time zone.
SC_VERSION
Posix version number. This will be 199009 if the underlying operating system's C interface conforms to ISO/IEC 9945-1:1990.

INTEGER,PARAMETER :: TIME_KIND

The integer kind used for holding date/time values (see TIME).
 

DERIVED-TYPE DESCRIPTION

TYPE TMS
       INTEGER(CLOCK_TICK_KIND) UTIME, STIME, CUTIME, CSTIME
END TYPE
Derived type holding CPU usage time in clock ticks. UTIME and STIME contain CPU time information for a process, CUTIME and CSTIME contain CPU time information for its terminated child processes. In each case this is divided into user time (UTIME, CUTIME) and system time (STIME, CSTIME).

TYPE UTSNAME
       CHARACTER*(...) SYSNAME, NODENAME, RELEASE, VERSION, MACHINE
END TYPE

Derived type holding data returned by UNAME. Note that the character length of each component is fixed, but may be different on different systems. The values in these components are blank-padded (if short) or truncated (if long). For further information see ISO/IEC 9945-1:1990.
 

PROCEDURE DESCRIPTIONS

PURE INTEGER (KIND=CLOCK_TICK_KIND) FUNCTION CLK_TCK()
Returns the number of clock ticks in one second of CPU time (see TIMES).

PURE SUBROUTINE CTERMID(S,LENS)
CHARACTER*(*),OPTIONAL,INTENT(OUT) :: S
INTEGER,OPTIONAL,INTENT(OUT) :: LENS

If present, LENS is set to the length of the filename of the controlling terminal. If present, S is set to the filename of the controlling terminal. If S is longer than the filename of the controlling terminal it is padded with blanks; if S is shorter it is truncated - it is the user's responsibility to check the value of LENS to detect such truncation.

If the filename of the controlling terminal cannot be determined for any reason LENS (if present) will be set to zero and S (if present) will be blank.

SUBROUTINE GETARG(K,ARG,LENARG,ERRNO)
INTEGER,INTENT(IN) :: K
CHARACTER*(*),OPTIONAL,INTENT(OUT) :: ARG
INTEGER,OPTIONAL,INTENT(OUT) :: LENARG, ERRNO

Accesses command-line argument number K, where argument zero is the program name. If ARG is present, it receives the argument text (blank-padded or truncated as appropriate if the length of the argument differs from that of ARG). If ARGLEN is present, it receives the length of the argument. If ERRNO is present, it receives the error status.

Note that if K is less than zero or greater than the number of arguments (returned by IARGC) error EINVAL (see F90_UNIX_ERRNO) is raised.

PURE INTEGER FUNCTION GETEGID()

Returns the effective group number of the calling process.

SUBROUTINE GETENV(NAME,VALUE,LENVALUE,ERRNO)
CHARACTER*(*),INTENT(IN) :: NAME
CHARACTER*(*),OPTIONAL,INTENT(OUT) :: VALUE
INTEGER,OPTIONAL,INTENT(OUT) :: LENVALUE, ERRNO

Accesses the environment variable named by NAME. If VALUE is present, it receives the text value of the variable (blank-padded or truncated as appropriate if the length of the value differs from that of VALUE). If LENVALUE is present, it receives the length of the value. If ERRNO is present, it receives the error status.

If there is no such variable, error EINVAL (see F90_UNIX_ERRNO) is raised. Other possible errors include ENOMEM.

PURE INTEGER FUNCTION GETEUID()

Returns the effective user number of the calling process.

PURE INTEGER FUNCTION GETGID()

Returns the group number of the calling process.

SUBROUTINE GETGROUPS(GROUPLIST,NGROUPS,ERRNO)
INTEGER,OPTIONAL,INTENT(OUT) :: GROUPLIST(:), NGROUPS, ERRNO

Retrieves supplementary group number information for the calling process. If GROUPLIST is present, it is filled with the supplementary group numbers. If NGROUPS is present, it receives the number of supplementary group numbers. If ERRNO is present, it receives the error status.

If GROUPLIST is too small to contain the complete list of supplementary group numbers, error EINVAL (see F90_UNIX_ERRNO) is raised. The maximum number of supplementary group numbers can be found using SYSCONF (enquiry SC_NGROUPS_MAX); alternatively, CALL GETGROUPS(NGROUPS=N) will reliably return the actual number in use.

PURE SUBROUTINE GETHOSTNAME(NAME,LENNAME)
CHARACTER*(*),OPTIONAL,INTENT(OUT) :: NAME
INTEGER,OPTIONAL,INTENT(OUT) :: LENNAME

This provides the functionality of 4.3BSD's gethostname. If NAME is present it receives the text of the standard host name for the current processor, blank-padded or truncated if appropriate. If LENNAME is present it receives the length of the host name. If no host name is available LENNAME will be zero.

PURE SUBROUTINE GETLOGIN(S,LENS)
CHARACTER*(*),OPTIONAL,INTENT(OUT) :: S
INTEGER,OPTIONAL,INTENT(OUT) :: LENS

Accesses the user name (login name) associated with the calling process. If S is present, it receives the text of the name (blank-padded or truncated as appropriate if the length of the login name differs from that of S). If LENS is present, it receives the length of the login name.

PURE INTEGER FUNCTION GETPGRP()

Returns the process group number of the calling process.

PURE INTEGER FUNCTION GETPID()

Returns the process number of the calling process.

PURE INTEGER FUNCTION GETPPID()

Returns the process number of the parent of the calling process.

PURE INTEGER FUNCTION GETUID()

Returns the user number of the calling process.

PURE INTEGER FUNCTION IARGC()

Returns the number of command-line arguments. This will be -1 if even the program name is unavailable.

SUBROUTINE ISATTY(LUNIT,ANSWER,ERRNO)
INTEGER,INTENT(IN) :: LUNIT
LOGICAL,INTENT(OUT) :: ANSWER
INTEGER,OPTIONAL,INTENT(OUT) :: ERRNO

ANSWER receives the value .TRUE. if and only if logical unit LUNIT is connected to a terminal.

If LUNIT is not a valid unit number or is not connected to any file, error EBADF (see F90_UNIX_ERRNO) is raised.

SUBROUTINE SETGID(GID,ERRNO)
INTEGER,INTENT(IN) :: GID
INTEGER,OPTIONAL,INTENT(OUT) :: ERRNO

Sets the group number of the calling process to GID. For full details refer to section 4.2.2 of ISO/IEC 9945-1:1990.

If GID is not a valid group number, error EINVAL (see F90_UNIX_ERRNO) is raised. If the process is not allowed to set the group number to GID, error EPERM is raised.

SUBROUTINE SETPGID(PID,PGID,ERRNO)
INTEGER,INTENT(IN) :: PID, PGID
INTEGER,OPTIONAL,INTENT(OUT) :: ERRNO

Sets the process group number of process PID (or, if PID is zero, the calling process) to PGID. For full details refer to section 4.3.3 of ISO/IEC 9945-1:1990.

Possible errors include EACCES, EINVAL, ENOSYS, EPERM, ESRCH (see F90_UNIX_ERRNO).

SUBROUTINE SETSID(SID,ERRNO)
INTEGER,INTENT(IN) :: SID
INTEGER,OPTIONAL,INTENT(OUT) :: ERRNO

Creates a session and sets the process group number of the calling process. For full details refer to section 4.3.2 of ISO/IEC 9945-1:1990.

Possible errors include EPERM (see F90_UNIX_ERRNO).

SUBROUTINE SETUID(UID,ERRNO)
INTEGER,INTENT(IN) :: UID
INTEGER,OPTIONAL,INTENT(OUT) :: ERRNO

Sets the user number of the calling process to UID. For full details refer to section 4.2.2 of ISO/IEC 9945-1:1990.

If UID is not a valid group number, error EINVAL (see F90_UNIX_ERRNO) is raised. If the process is not allowed to set the user number to UID, error EPERM is raised.

SUBROUTINE SYSCONF(NAME,VAL,ERRNO)
INTEGER,INTENT(IN) :: NAME
INTEGER(LONG_KIND),INTENT(OUT) :: VAL
INTEGER,OPTIONAL,INTENT(OUT) :: ERRNO

Returns the value of a system configuration variable. The variables are named by integer PARAMETERs defined in this module, and are described in the PARAMETER DESCRIPTION section.

If NAME is not a valid configuration variable name, error EINVAL (see F90_UNIX_ERRNO) is raised.

SUBROUTINE TIME(ITIME,ERRNO)
INTEGER(TIME_KIND),INTENT(OUT) :: ITIME
INTEGER,OPTIONAL,INTENT(OUT) :: ERRNO

ITIME receives the operating system date/time in seconds since the Epoch.

INTEGER(KIND=CLOCK_TICK_KIND) FUNCTION TIMES(BUFFER)
TYPE(TMS),INTENT(OUT) :: BUFFER

This function returns the elapsed real time in clock ticks since an arbitrary point in the past, or -1 if the function is unavailable. BUFFER is filled in with CPU time information for the calling process and any terminated child processes.

If this function returns zero the values in BUFFER will still be correct but the elapsed-time timer was not available.

SUBROUTINE TTYNAME(LUNIT,S,LENS,ERRNO)
INTEGER,INTENT(IN) :: LUNIT
CHARACTER*(*),OPTIONAL,INTENT(OUT) :: S
INTEGER,OPTIONAL,INTENT(OUT) :: LENS, ERRNO

Accesses the name of the terminal connected to logical unit LUNIT. If S is present, it receives the text of the terminal name (blank-padded or truncated as appropriate, if the length of the terminal name differs from that of S). If LENS is present, it receives the length of the terminal name. If ERRNO is present, it receives the error status.

If LUNIT is not a valid logical unit number, or is not connected, error EBADF (see F90_UNIX_ERRNO) is raised.

SUBROUTINE UNAME(NAME,ERRNO)
TYPE(UTSNAME),INTENT(OUT) :: NAME
INTEGER,OPTIONAL,INTENT(OUT) :: ERRNO

Returns information about the operating system in NAME.
 

SEE ALSO

f90_unix_errno(3), f95(1), nag_modules(3).  

BUGS

Please report any bugs found to "support@nag.co.uk", along with any suggestions for improvements.

© The Numerical Algorithms Group Ltd, Oxford UK. 2001